<?php
/***************************************************************************
 *   copyright : (C) 2009 Udrea Cristian
 *   site : http://code.google.com/p/testauction-php
 ***************************************************************************/

/***************************************************************************
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as 
 *   published by the Free Software Foundation; either version 2 of the
 *   License, or (at your option) any later version. Although none of the
 *   code may be sold. If you have been sold this script, get a refund.
 ***************************************************************************/
include("include/classes/class.AuctionHandler.php");
class AuctionActive extends Element {
	public function __construct() {
		$this->attributes['AuctionID'] = 0;
		$this->attributes['OneTime24h'] = FALSE;
		$this->attributes['FreshAuction'] = FALSE;
	}
	public function setAuctionID($ID) {
		global $auctionDB;
		$this->setAttribute('AuctionID', $ID);
		$auction_info = $auctionDB->getAuctionData($_GET['id']);
		$this->setAttribute('OneTime24h', ($auction_info['one_time_24h']) ? TRUE : FALSE);
		$this->setAttribute('FreshAuction', ($auction_info['fresh_auction']) ? TRUE : FALSE);
	}
	public function toString() {
		global $session, $auctionDB;
		$info = $auctionDB->getAuctionData($this->getAttribute('AuctionID'));
		$productinfo = $auctionDB->getProductData($info['product_id']);
		$latestoffer = $auctionDB->getAuctionLatestOffer($info['auction_id']);

		$PRICE = $auctionDB->getAuctionOfferCount($info['auction_id'])*$info['offer_increment']+$info['base_price'];
		$LASTBIDDER = $latestoffer['username'];
		$PRODUCTNAME = $productinfo['product_name'];       //GET ACTUAL PRODUCT NAME
		$PRODUCTPHOTOSMALL = "small_".$productinfo['pict1_url']; //GET ACTUAL SMALL PHOTO
		$STARTDATE = date("j/n/Y H:i", $info['starts_timestamp']);
		
		$min = (integer)$info['time_left'] / 60;
		$sec = $info['time_left'] % 60;
 
		return "<div id=\"auctionbox_" . $info['auction_id'] . "\" class=\"box_green\">".
		"<h2><a href=\"main.php?page=24&id=" . $info['auction_id'] . "\">" . $PRODUCTNAME . "</a></h2>".
		"<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\" style=\"text-align: center\">".
		"<tr><td>&nbsp;</td>".
		"<td rowspan=\"4\" style=\"border: 2px solid black\" width=\"120\" height=\"90\">".
		"<a href=\"main.php?page=24&id=" . $info['auction_id'] . "\">".
		"<img src=\"produse/" . $PRODUCTPHOTOSMALL . "\" alt=\"" . $PRODUCTNAME . "\" title=\"".$PRODUCTNAME."\"/></a>".
		"</td></tr>".
		"<tr><td><b class=\"IEFIX_timer_counter\" id=\"lblTime_" . $info['auction_id'] . "\" style=\"color: #1F55F0;\">" . 
		(($auction_info['starts_timestamp'] > time()) ? $STARTDATE : "") . "</b></td></tr>".
		"<tr><td class=\"timer\" id=\"lblTimeCounter_" . $info['auction_id'] . "\"></td></tr>".
		"<tr><td class=\"IEFIX_bidder_state\" id=\"lblBestBidderState_" . $info['auction_id'] . "\" style=\"color: #50000D; font-weight: bold\">Ultimul ofertant:</td></tr>".
		"<tr><td colspan=\"2\" id=\"lblBestBidder_" . $info['auction_id'] . "\" style=\"color: #50000D; font-weight: bold\">" . $LASTBIDDER . "</td></tr>".
		"<tr><td><span id=\"auction_button_" . $info['auction_id'] . "\">".
		($session->logged_in ?
			"<button class=\"green-button\" onclick=\"putbid('" . $info['auction_id'] . "', '" . $session->userid . "', event);\">OFERA</button>" : 
			"<button class=\"green-button\" onclick=\"showHideAlert('Trebuie sa te autentifici mai intai!', event);\">OFERA</button>"
		)."</span></td>".
		"<td style=\"font-size: 14px; font-weight: bold\"><span id=\"lblPrice_" . $info['auction_id'] . "\">" . $PRICE . "</span>&nbsp;CREDITS</td>".
		"</tr></table></div>";
	}
}
$auctionactive_box = new AuctionActive();
?>
